#!/usr/bin/python
# -- coding:utf8 --

# 线上部署代码
import os
import sys
sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
# import util_log as utils
from model_phl.utils import select_sql_mysql_v1
from model_phl.my_tool_package import get_is_none

import requests
import pandas as pd
import numpy as np
import json
import re
import warnings

warnings.filterwarnings("ignore")



def get_cal_division(numerator, denominator):
    try:
        if denominator == 0:
            return -999978
        elif get_is_none(numerator) or get_is_none(denominator):
            return -999977
        else:
            return round(numerator / denominator, 2)
    except Exception as e:
        return -999976


def get_condition_df(df, condition_field, match_list='none'):
    """
    找到满足content属于某一类别的数据,精确匹配
    :param df:
    :param condition_field:
    :param match_list:
    :return:
    """
    if df.empty:
        return pd.DataFrame()
    df_tmp = df.copy().reset_index(drop=True)
    # 找到满足时间窗口的数据
    if match_list == 'none':
        return df_tmp
    else:
        return df_tmp[df_tmp[condition_field].isin(match_list)]


def get_list_value_is_in_str(match_list, params_str):
    """
    检查文本信息是否再匹配列表里面
    :param match_list:
    :param params_str:
    :return:
    """
    for v in match_list:
        if type(v) == list:
            flg = 1
            for v_ in v:
                if str(v_).strip().lower() not in str(params_str).strip().lower():
                    flg = 0
            if flg == 1:
                return 1
        else:
            if str(v).strip().lower() in str(params_str).strip().lower():
                return 1
    return 0


def get_which_value_in_list(match_list, params_str):
    for v in match_list:
        if type(v) == list:
            flg = 1
            for v_ in v:
                if str(v_).strip().lower() not in str(params_str).strip().lower():
                    flg = 0
            if flg == 1:
                return str(v_).strip().lower()
        else:
            if str(v).strip().lower() in str(params_str).strip().lower():
                return str(v).strip().lower()
    return 'None'


def get_condition_fuzzy_df(df, condition_field, match_list='none'):
    """
     找到满足content属于某一类别的数据,模糊匹配
    :param df:
    :param condition_field:
    :param match_list:
    :return:
    """
    if df.empty:
        return pd.DataFrame()
    df_tmp = df.copy().reset_index(drop=True)
    # 找到满足时间窗口的数据
    if match_list == 'none':
        return df_tmp
    else:
        return df_tmp[df_tmp[condition_field].apply(lambda x: get_list_value_is_in_str(match_list, x) == 1)]


def get_label_content(x, key_dict, cal_list):
    """
    给文本信息打上标签信息
    :param x:
    :param key_dict:
    :param cal_list:
    :return:
    """
    label_list = ['All']
    for key in cal_list:
        if key == 'All':
            continue
        else:
            match_list = key_dict[key]
            if get_list_value_is_in_str(match_list, x) == 1:
                label_list.append(key)
    return list(set(label_list))


def get_windows_aggregation_main(df, con, dt, con_key, cal_field, cal_type, condition_dict_all, dt_dict):
    """
    统计聚合函数
    :param df:
    :param con:
    :param dt:
    :param con_key:
    :param cal_field:
    :param cal_type:
    :param condition_dict_all:
    :param dt_dict:
    :return:
    """
    df_tmp = df.copy()
    df_tmp[cal_field] = df_tmp[cal_field].apply(lambda x: np.nan if (get_is_none(x) == True) else x)
    default_list = [cal_field]
    df_time_tmp = df_tmp[dt_dict[dt]]
    if df_time_tmp.empty:
        df_time_tmp = pd.DataFrame(columns=default_list)
    df_con_tmp = df_tmp[condition_dict_all[con] & dt_dict[dt] & condition_dict_all[con_key]]
    df_con_tmp = df_con_tmp[pd.isnull(df_con_tmp[cal_field]) == False]
    if df_con_tmp.empty:
        df_con_tmp = pd.DataFrame(columns=default_list)
    if cal_type == 'Cnt':
        re_value = df_con_tmp[cal_field].count()
        if df_con_tmp.empty:
            re_value = -999999
    elif cal_type == 'DistinctCnt':
        re_value = df_con_tmp[cal_field].nunique()
        if df_con_tmp.empty:
            re_value = -999999
    elif cal_type == 'RepeatCnt':
        unique_cnt = df_con_tmp[cal_field].nunique()
        _cnt = df_con_tmp[cal_field].count()
        if df_con_tmp.empty:
            re_value = -999999
        else:
            re_value = _cnt - unique_cnt
    elif cal_type == 'Std':
        if df_con_tmp.empty:
            re_value = -999999
        else:
            re_value = round(df_con_tmp[cal_field].std(), 2)
    elif cal_type == 'Avg':
        if df_con_tmp.empty:
            re_value = -999999
        else:
            re_value = round(df_con_tmp[cal_field].mean(), 2)
    elif cal_type == 'Max':
        if df_con_tmp.empty:
            re_value = -999999
        else:
            re_value = round(df_con_tmp[cal_field].max(), 2)
    elif cal_type == 'Min':
        if df_con_tmp.empty:
            re_value = -999999
        else:
            re_value = round(df_con_tmp[cal_field].min(), 2)
    elif cal_type == 'Sum':
        if df_con_tmp.empty:
            re_value = -999999
        else:
            re_value = round(df_con_tmp[cal_field].sum(), 2)
    elif cal_type == 'Pct':
        df_dem_tmp = df_tmp[condition_dict_all[con] & dt_dict[dt]]
        dem = df_dem_tmp[cal_field].count()
        num = df_con_tmp[cal_field].count()
        if df_dem_tmp.empty:
            dem = -999999
        if df_con_tmp.empty:
            num = -999999
        if df_dem_tmp.empty and df_con_tmp.empty:
            re_value = -999999
        else:
            re_value = get_cal_division(num, dem)
    elif cal_type == 'PctV2':
        df_dem_tmp = df_tmp[condition_dict_all[con_key] & dt_dict[dt]]
        dem = df_dem_tmp[cal_field].count()
        num = df_con_tmp[cal_field].count()
        if df_dem_tmp.empty:
            dem = -999999
        if df_con_tmp.empty:
            num = -999999
        if df_dem_tmp.empty and df_con_tmp.empty:
            re_value = -999999
        else:
            re_value = get_cal_division(num, dem)
    elif cal_type == 'DistinctPct':
        dem = df_con_tmp[cal_field].count()
        num = df_con_tmp[cal_field].nunique()
        if df_con_tmp.empty:
            re_value = -999999
        else:
            re_value = get_cal_division(num, dem)
    elif cal_type == 'NuniquePct':
        df_dem_tmp = df_tmp[condition_dict_all[con] & dt_dict[dt]]
        dem = df_dem_tmp[cal_field].nunique()
        num = df_con_tmp[cal_field].nunique()
        if df_dem_tmp.empty:
            dem = -999999
        if df_con_tmp.empty:
            num = -999999
        if df_dem_tmp.empty and df_con_tmp.empty:
            re_value = -999999
        else:
            re_value = get_cal_division(num, dem)
    elif cal_type == 'NuniquePctV2':
        df_dem_tmp = df_tmp[condition_dict_all[con_key] & dt_dict[dt]]
        dem = df_dem_tmp[cal_field].nunique()
        num = df_con_tmp[cal_field].nunique()
        if df_dem_tmp.empty:
            dem = -999999
        if df_con_tmp.empty:
            num = -999999
        if df_dem_tmp.empty and df_con_tmp.empty:
            re_value = -999999
        else:
            re_value = get_cal_division(num, dem)
    elif cal_type == 'RepeatPct':
        cnt_dem = df_con_tmp[cal_field].count()
        unique_cnt_num = df_con_tmp[cal_field].nunique()
        num = cnt_dem - unique_cnt_num
        if df_con_tmp.empty:
            re_value = -999999
        else:
            re_value = get_cal_division(num, cnt_dem)
    elif cal_type == 'Median':
        if df_con_tmp.empty:
            re_value = -999999
        else:
            re_value = round(df_con_tmp[cal_field].median(), 2)
    elif cal_type == 'Skew':
        if df_con_tmp.empty:
            re_value = -999999
        else:
            re_value = round(df_con_tmp[cal_field].skew(), 2)
    elif cal_type == 'Mad':
        if df_con_tmp.empty:
            re_value = -999999
        else:
            re_value = round(df_con_tmp[cal_field].mad(), 2)
    else:
        re_value = -999999
    if str(re_value).lower().strip() in ['nan']:
        re_value = -999999
    return re_value


def get_which_match_key_words(x, keywords_list):
    """
    匹配关键词方法，返回匹配的关键词，循环的方式，若匹配到列表中的某一关键词，则返回匹配的关键词
    :param x:
    :param keywords_list:
    :return:
    """
    for keyword in keywords_list:
        if type(keyword) == list:
            flg = 1
            for keyword_ in keyword:
                if str(keyword_).strip().lower() not in str(x).strip().lower():
                    flg = 0
            if flg == 1:
                return keyword
        if str(keyword).strip().lower() in str(x).strip().lower():
            keywords = str(keyword).strip().lower()
            matchObj = re.match(r'[(\[]+.*?{}.*?[)\]]+'.format(keywords), str(x), re.M | re.I)
            if matchObj:
                if len(str(matchObj.group()).strip().lower().split(' ')) > 3:
                    continue
                return (re.sub(r'[()\[\]\s{}]', '', str(matchObj.group()).strip().lower()))
            else:
                return keyword
    else:
        return 'none'


def get_extra_organization(x):
    try:
        result_list = re.findall(r"(:?[\s]*[\(<\[\{]+[\s]*(.*?)[\s]*[\)>\]\}]+)", str(x))
        result_ = 'None'
        if len(result_list) > 0:
            for value in result_list[0]:
                result_ = re.sub('[^a-z\sA-Z]', '', str(value).strip().lower())
                if get_is_none(result_) == False:
                    return str(result_).replace(' ', '')
        return result_
    except Exception as e:
        return 'None'


# 用于金额提取的正则匹配技术
normal_reg_list = [(r"((php)?\s?[\.,\d]+\d\s?(php)?)", 'php'), (r"((p)?[\.,\d]+\d(p)?)", 'p'),
                   ('((amount)\s?[\.,\d]+\d)', 'amount')]

gcash_balance_list = [(r"((balance is php)?\s?[\.,\d]+\d\s?)", 'balance is php'),
                      (r"((balance is p)?\s?[\.,\d]+\d\s?)", 'balance is p')]


def extract_money(s, reg_list):
    try:
        if get_is_none(s):
            return 0
        total_list = list()
        for r in reg_list:
            temp_list = re.findall(r[0], s, re.I)
            total_list = total_list + [x[0] for x in temp_list if r[1] in x[0]]
        if len(total_list) <= 0:
            return 0
        money = total_list[0]
        for r in reg_list:
            money = money.replace(r[1], '')
        money_value = float(money.replace(',', '').strip())
        return money_value
    except Exception as ex:
        return 0


# 获取sms_df数据集
def get_sms_df(ApplyNO):
    # 第一步：获取URL链接
    file_url_sql = """
    select 
    ApplyNO
    ,FileUrl
    from BindingFileUrl
    where ApplyNO = '{}'
    """.format(ApplyNO)
    url_df = select_sql_mysql_v1(file_url_sql)

    # 第二步：获取数据集
    response = requests.get(url_df['FileUrl'][0])
    if response.status_code == 200:
        json_data = response.json()
    else:
        print(f"Failed to download {url_df['FileUrl'][0]}, status code: {response.status_code}")

    # 第三步：解析sms数据
    json_data1 = eval(json_data)
    try:
        # 第四步：SMS数据框
        sms_df = pd.DataFrame(json.loads(json_data1['smss']))
        sms_df['ApplyNO'] = ApplyNO
    except Exception as e:
        print(f"请求失败，错误信息: {str(e)}")

    # 第四步：获取申请时间
    apply_date_sql = """
        select 
        ApplyNO
        ,ApplyDate
        from SysJkApply
        where ApplyNO = '{}'
        """.format(ApplyNO)
    applydate_df = select_sql_mysql_v1(apply_date_sql)

    # 第五步：数据合并
    sms_df = sms_df.merge(applydate_df)

    return sms_df

# 第二步：短信数据格式化
def get_format_data(sms_data):
    try:
        
        file_path_name = './model/message_type_dict.json'
        current_path = os.path.dirname(__file__)

        file_path_name1 = file_path_name.replace("./", current_path + "/")
        with open(file_path_name1, 'r') as f:
            message_type_dict = json.loads(f.read())
        
        # sms_data = get_sms_df(ApplyNO)
        if sms_data.empty:
            return pd.DataFrame()
        sms_data['TimeInterval'] = (
                pd.to_datetime(sms_data['ApplyDate']) - pd.to_datetime(sms_data['send_time'])).dt.total_seconds()
        sms_data.loc[:, 'Money'] = sms_data['sms_content'].apply(lambda x: extract_money(x, normal_reg_list))
        sms_data.loc[:, 'Balance'] = sms_data['sms_content'].apply(lambda x: extract_money(x, gcash_balance_list))
        sms_data.loc[:, 'msgPlat'] = sms_data['sms_content'].apply(lambda x: get_extra_organization(x))
        sms_data.loc[:, 'msgPlat'] = sms_data[['msgPlat', 'send_mobile']].apply(
            lambda x: str(x['send_mobile']).replace(' ', '').lower() if x['msgPlat'] == 'None' else x['msgPlat'],
            axis=1)
        sms_data['MessageDays'] = sms_data['send_time'].apply(lambda x: str(x).split()[0])
        sms_data.rename(columns={'sms_content': 'Msg', 'send_mobile': 'Phone'}, inplace=True)

        sms_key_list = ['All', 'Finance', 'Bank',
                        'Overdue', 'OverdueRemind', 'LoanSuccess', 'RepaySuccess',
                        'RepayRemind', 'Verification', 'Airtime', 'PayIn', 'PayOut',
                        'msgPlatBank', 'msgPlatFinance']

        msgPlat_list = ['All', 'msgPlatBank', 'Finance', 'msgPlatFinance', 'Operator']

        sms_data['Msglabel'] = sms_data['Msg'].apply(
            lambda x: get_label_content(x, message_type_dict, sms_key_list))
        sms_data['msgPlatlabel'] = sms_data['msgPlat'].apply(
            lambda x: get_label_content(x, message_type_dict, msgPlat_list))
        sms_data['conLabel'] = sms_data[['Msglabel', 'msgPlatlabel']].apply(
            lambda x: list(set(set(x['Msglabel']) | set(x['msgPlatlabel']))), axis=1)
        cal_field_list = ['Msg', 'MessageDays', 'Phone', 'msgPlat', 'TimeInterval', 'Money', 'Balance']
        for cal_field in cal_field_list:
            sms_data[cal_field] = sms_data[cal_field].apply(
                lambda x: np.nan if get_is_none(x) == True else x)
        return sms_data
    except Exception as e:
        # utils.get_logger().error(e)
        print(f"错误信息: {str(e)}")
        return pd.DataFrame()


def get_free_sms_features(sms_data):
    """
    获取sms数据集和计算sms特征集
    :param phone_sub:
    :param ApplyNO:
    :return:
    """
    sms_data = get_format_data(sms_data)
    sms_data = calculate_sms_features(sms_data)
    return sms_data


def calculate_sms_features(sms_data):
    """
    获取sms数据集和计算sms特征集
    :param phone_sub:
    :param ApplyNO:
    :return:
    """
    try:
        if sms_data.empty:
            return {
                # 新客模型第四版
                'smsAllOverdueRemindTimeIntervalMin3D': -999999,
                'smsAllRepayRemindTimeIntervalMax60D': -999999,
                'smsAllOverdueRemindTimeIntervalStd60D': -999999,
                'smsFinancemsgPlatBankTimeIntervalMinAllD': -999999,
                'smsAllAllTimeIntervalStd60D': -999999,
                'smsAllOverdueRemindTimeIntervalMinAllD': -999999,
                'smsAllVerificationmsgPlatNunique14D': -999999,
                'smsFinanceRepayRemindTimeIntervalMedianAllD': -999999,
                'smsAllOverdueRemindTimeIntervalStdAllD': -999999,
                'smsFinanceRepayRemindTimeIntervalStdAllD': -999999,
                'smsAllPayOutMessageDaysNuniqueAllD': -999999,
                'smsAllRepayRemindTimeIntervalStd14D': -999999,
                'smsAllAllMoneyMax7D': -999999,
                'smsAllOverdueTimeIntervalStdAllD': -999999,
                'smsAllPayInMsgNuniqueAllD': -999999,
                'smsAllLoanSuccessTimeIntervalStdAllD': -999999,
                'smsAllFinanceTimeIntervalMax14D': -999999,
                'smsFinanceVerificationTimeIntervalMinAllD': -999999,
                'smsAllmsgPlatFinanceMoneyStd3D': -999999,
                'smsAllAllTimeIntervalMedianAllD': -999999,
                'smsFinanceRepayRemindTimeIntervalMin60D': -999999,
                'smsAllRepaySuccessTimeIntervalMin7D': -999999,
                'smsAllRepaySuccessTimeIntervalMinAllD': -999999,
                'smsAllAllMsgNuniqueAllD': -999999,
                'smsAllVerificationTimeIntervalMedian60D': -999999

            }

        df_tmp1 = sms_data.copy()
        # 筛选符合条件的数据
        con_field_list = ['All',  'RepayRemind', 'LoanSuccess', 'RepaySuccess', 'OverdueRemind', 'Finance',
                          'Verification', 'PayOut', 'Overdue', 'PayIn', 'msgPlatFinance', 'RepaySuccess', 'msgPlatBank']
        condition_dict_all = {}
        df_tmp1['All'] = 1
        for con in con_field_list:
            if con in ['All']:
                index = df_tmp1.All.ge(1)
            else:
                index = df_tmp1.conLabel.apply(lambda x: con in x)
            condition_dict_all[con] = index

        # 时间条件
        dt_dict = {}
        dt_list = ['All', 1, 3, 7, 14, 30, 60]
        for dt in dt_list:
            if dt in ['All']:
                index = df_tmp1.All.ge(1)
            else:
                index = df_tmp1.TimeInterval.isin(range(0, dt * 24 * 3600))
            dt_dict[dt] = index

        # 特征的计算逻辑
        smsAllOverdueRemindTimeIntervalMin3D = get_windows_aggregation_main(df_tmp1, 'All', 3, 'OverdueRemind',
                                                                            'TimeInterval', 'Min', condition_dict_all,
                                                                            dt_dict)
        smsAllRepayRemindTimeIntervalMax60D = get_windows_aggregation_main(df_tmp1, 'All', 60, 'RepayRemind',
                                                                            'TimeInterval', 'Max', condition_dict_all,
                                                                            dt_dict)

        smsAllOverdueRemindTimeIntervalStd60D = get_windows_aggregation_main(df_tmp1, 'All', 60, 'OverdueRemind',
                                                                            'TimeInterval', 'Std', condition_dict_all,
                                                                            dt_dict)
        smsFinancemsgPlatBankTimeIntervalMinAllD = get_windows_aggregation_main(df_tmp1, 'Finance', 'All', 'msgPlatBank',
                                                                            'TimeInterval', 'Min', condition_dict_all,
                                                                            dt_dict)
        smsAllAllTimeIntervalStd60D = get_windows_aggregation_main(df_tmp1, 'All', 60, 'All',
                                                                            'TimeInterval', 'Std', condition_dict_all,
                                                                            dt_dict)

        smsAllOverdueRemindTimeIntervalMinAllD = get_windows_aggregation_main(df_tmp1, 'All', 'All', 'OverdueRemind',
                                                                            'TimeInterval', 'Min', condition_dict_all,
                                                                            dt_dict)
        smsAllVerificationmsgPlatNunique14D = get_windows_aggregation_main(df_tmp1, 'All', 14, 'Verification',
                                                                            'msgPlat', 'DistinctCnt', condition_dict_all,
                                                                            dt_dict)
        smsFinanceRepayRemindTimeIntervalMedianAllD = get_windows_aggregation_main(df_tmp1, 'Finance', 'All', 'RepayRemind',
                                                                            'TimeInterval', 'Median', condition_dict_all,
                                                                            dt_dict)
        smsAllOverdueRemindTimeIntervalStdAllD = get_windows_aggregation_main(df_tmp1, 'All', 'All', 'OverdueRemind',
                                                                            'TimeInterval', 'Std', condition_dict_all,
                                                                            dt_dict)
        smsFinanceRepayRemindTimeIntervalStdAllD = get_windows_aggregation_main(df_tmp1, 'Finance', 'All', 'RepayRemind',
                                                                            'TimeInterval', 'Std', condition_dict_all,
                                                                            dt_dict)
        smsAllPayOutMessageDaysNuniqueAllD = get_windows_aggregation_main(df_tmp1, 'All', 'All', 'PayOut',
                                                                            'MessageDays', 'DistinctCnt', condition_dict_all,
                                                                            dt_dict)
        smsAllRepayRemindTimeIntervalStd14D = get_windows_aggregation_main(df_tmp1, 'All', 14, 'RepayRemind',
                                                                            'TimeInterval', 'Std', condition_dict_all,
                                                                            dt_dict)
        smsAllAllMoneyMax7D = get_windows_aggregation_main(df_tmp1, 'All', 7, 'All',
                                                                            'Money', 'Max', condition_dict_all,
                                                                            dt_dict)
        smsAllOverdueTimeIntervalStdAllD = get_windows_aggregation_main(df_tmp1, 'All', 'All', 'Overdue',
                                                                            'TimeInterval', 'Std', condition_dict_all,
                                                                            dt_dict)
        smsAllPayInMsgNuniqueAllD = get_windows_aggregation_main(df_tmp1, 'All', 'All', 'PayIn',
                                                                            'Msg', 'DistinctCnt', condition_dict_all,
                                                                            dt_dict)
        smsAllLoanSuccessTimeIntervalStdAllD = get_windows_aggregation_main(df_tmp1, 'All', 'All', 'LoanSuccess',
                                                                            'TimeInterval', 'Std', condition_dict_all,
                                                                            dt_dict)
        smsAllFinanceTimeIntervalMax14D = get_windows_aggregation_main(df_tmp1, 'All', 14, 'Finance',
                                                                            'TimeInterval', 'Max', condition_dict_all,
                                                                            dt_dict)
        smsFinanceVerificationTimeIntervalMinAllD = get_windows_aggregation_main(df_tmp1, 'Finance', 'All', 'Verification',
                                                                            'TimeInterval', 'Min', condition_dict_all,
                                                                            dt_dict)
        smsAllmsgPlatFinanceMoneyStd3D = get_windows_aggregation_main(df_tmp1, 'All', 3, 'msgPlatFinance',
                                                                            'Money', 'Std', condition_dict_all,
                                                                            dt_dict)
        smsAllAllTimeIntervalMedianAllD = get_windows_aggregation_main(df_tmp1, 'All', 'All', 'All',
                                                                            'TimeInterval', 'Median', condition_dict_all,
                                                                            dt_dict)
        smsFinanceRepayRemindTimeIntervalMin60D = get_windows_aggregation_main(df_tmp1, 'Finance', 60, 'RepayRemind',
                                                                            'TimeInterval', 'Min', condition_dict_all,
                                                                            dt_dict)
        smsAllRepaySuccessTimeIntervalMin7D = get_windows_aggregation_main(df_tmp1, 'All', 7, 'RepaySuccess',
                                                                            'TimeInterval', 'Min', condition_dict_all,
                                                                            dt_dict)
        smsAllRepaySuccessTimeIntervalMinAllD = get_windows_aggregation_main(df_tmp1, 'All', 'All', 'RepaySuccess',
                                                                            'TimeInterval', 'Min', condition_dict_all,
                                                                            dt_dict)
        smsAllAllMsgNuniqueAllD = get_windows_aggregation_main(df_tmp1, 'All', 'All', 'All',
                                                                            'Msg', 'DistinctCnt', condition_dict_all,
                                                                            dt_dict)
        smsAllVerificationTimeIntervalMedian60D = get_windows_aggregation_main(df_tmp1, 'All', 60, 'Verification',
                                                                            'TimeInterval', 'Median', condition_dict_all,
                                                                            dt_dict)




        return {

            'smsAllOverdueRemindTimeIntervalMin3D': smsAllOverdueRemindTimeIntervalMin3D,
            'smsAllRepayRemindTimeIntervalMax60D': smsAllRepayRemindTimeIntervalMax60D,
            'smsAllOverdueRemindTimeIntervalStd60D': smsAllOverdueRemindTimeIntervalStd60D,
            'smsFinancemsgPlatBankTimeIntervalMinAllD': smsFinancemsgPlatBankTimeIntervalMinAllD,
            'smsAllAllTimeIntervalStd60D': smsAllAllTimeIntervalStd60D,
            'smsAllOverdueRemindTimeIntervalMinAllD': smsAllOverdueRemindTimeIntervalMinAllD,
            'smsAllVerificationmsgPlatNunique14D': smsAllVerificationmsgPlatNunique14D,
            'smsFinanceRepayRemindTimeIntervalMedianAllD': smsFinanceRepayRemindTimeIntervalMedianAllD,
            'smsAllOverdueRemindTimeIntervalStdAllD': smsAllOverdueRemindTimeIntervalStdAllD,
            'smsFinanceRepayRemindTimeIntervalStdAllD': smsFinanceRepayRemindTimeIntervalStdAllD,
            'smsAllPayOutMessageDaysNuniqueAllD': smsAllPayOutMessageDaysNuniqueAllD,
            'smsAllRepayRemindTimeIntervalStd14D': smsAllRepayRemindTimeIntervalStd14D,
            'smsAllAllMoneyMax7D': smsAllAllMoneyMax7D,
            'smsAllOverdueTimeIntervalStdAllD': smsAllOverdueTimeIntervalStdAllD,
            'smsAllPayInMsgNuniqueAllD': smsAllPayInMsgNuniqueAllD,
            'smsAllLoanSuccessTimeIntervalStdAllD': smsAllLoanSuccessTimeIntervalStdAllD,
            'smsAllFinanceTimeIntervalMax14D': smsAllFinanceTimeIntervalMax14D,
            'smsFinanceVerificationTimeIntervalMinAllD': smsFinanceVerificationTimeIntervalMinAllD,
            'smsAllmsgPlatFinanceMoneyStd3D': smsAllmsgPlatFinanceMoneyStd3D,
            'smsAllAllTimeIntervalMedianAllD': smsAllAllTimeIntervalMedianAllD,
            'smsFinanceRepayRemindTimeIntervalMin60D': smsFinanceRepayRemindTimeIntervalMin60D,
            'smsAllRepaySuccessTimeIntervalMin7D': smsAllRepaySuccessTimeIntervalMin7D,
            'smsAllRepaySuccessTimeIntervalMinAllD': smsAllRepaySuccessTimeIntervalMinAllD,
            'smsAllAllMsgNuniqueAllD': smsAllAllMsgNuniqueAllD,
            'smsAllVerificationTimeIntervalMedian60D': smsAllVerificationTimeIntervalMedian60D


        }
    except Exception as e:
        # utils.get_logger().error(e)
        print(f"错误信息: {str(e)}")
        return {
            # 新客模型第四版
            'smsAllOverdueRemindTimeIntervalMin3D': -999976,
            'smsAllRepayRemindTimeIntervalMax60D': -999976,
            'smsAllOverdueRemindTimeIntervalStd60D': -999976,
            'smsFinancemsgPlatBankTimeIntervalMinAllD': -999976,
            'smsAllAllTimeIntervalStd60D': -999976,
            'smsAllOverdueRemindTimeIntervalMinAllD': -999976,
            'smsAllVerificationmsgPlatNunique14D': -999976,
            'smsFinanceRepayRemindTimeIntervalMedianAllD': -999976,
            'smsAllOverdueRemindTimeIntervalStdAllD': -999976,
            'smsFinanceRepayRemindTimeIntervalStdAllD': -999976,
            'smsAllPayOutMessageDaysNuniqueAllD': -999976,
            'smsAllRepayRemindTimeIntervalStd14D': -999976,
            'smsAllAllMoneyMax7D': -999976,
            'smsAllOverdueTimeIntervalStdAllD': -999976,
            'smsAllPayInMsgNuniqueAllD': -999976,
            'smsAllLoanSuccessTimeIntervalStdAllD': -999976,
            'smsAllFinanceTimeIntervalMax14D': -999976,
            'smsFinanceVerificationTimeIntervalMinAllD': -999976,
            'smsAllmsgPlatFinanceMoneyStd3D': -999976,
            'smsAllAllTimeIntervalMedianAllD': -999976,
            'smsFinanceRepayRemindTimeIntervalMin60D': -999976,
            'smsAllRepaySuccessTimeIntervalMin7D': -999976,
            'smsAllRepaySuccessTimeIntervalMinAllD': -999976,
            'smsAllAllMsgNuniqueAllD': -999976,
            'smsAllVerificationTimeIntervalMedian60D': -999976

        }


if __name__ == '__main__':
    ApplyNO = '169873007701625291'
    sms_features = get_sms_df(ApplyNO)
    # sms_features = get_free_sms_features(ApplyNO)
    print(sms_features)

